<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
            新增
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="../../css/x-admin.css" media="all">
        <script type="text/javascript" src="../../js/jquery.min.js"></script>
        <script type="text/javascript" src="../../js/frame.js"></script>
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form">
                <div class="layui-form-item">
                    <input type="hidden" id="id" name="id"/>
                    <label for="rolename" class="layui-form-label">
                        <span class="x-red">*</span>角色名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="rolename" name="rolename" required="" lay-verify="required"
                        autocomplete="off" class="layui-input">
                    </div>
                    <button  class="layui-btn" lay-filter="update" lay-submit="">
                        确定
                    </button>
                </div>
            </form>
        </div>
        <script src="../../lib/layui/layui.js" charset="utf-8"></script>
        <script src="../../js/x-layui.js" charset="utf-8"></script>
        <script>
            $(function(){
                //获取当前用户信息
                $.ajax({
                    url:getContextPath()+"/html/getCurrentUser",
                    type:"post",
                    data:"",
                    success:function(data){
                        if(data.success!=false){
                            var user = data.content;
                            if(user==null){
                                window.location.href=getRootPath();
                            }
                        }
                    },
                    error:function(e){
                        alert("系统错误，请联系管理员！！");
                    }
                });

                //查询用户信息
                $.ajax({
                    url:getContextPath()+"/html/findRoleById",
                    type:"post",
                    data:{id:getParam("id")},
                    success:function(data){
                        if(data.success!=false){
                            var role = data.content;
                            if(role!=null){
                                $("#id").val(getParam("id"));
                                $("#rolename").val(role.roleName);
                            }
                        }
                    },
                    error:function(e){
                        alert("系统错误，请联系管理员！！");
                    }
                });

            });
            layui.use(['form','layer'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,layer = layui.layer;

              //监听提交
              form.on('submit(update)', function(data){
                console.log(data);
                // alert(JSON.stringify(data.field));
                //发异步
                  $.ajax({
                      url:getContextPath()+"/html/updateRole",
                      type:"post",
                      data: JSON.parse(JSON.stringify(data.field)),
                      success:function(res){
                          if(res.success!=false){
                              layer.alert("修改成功", {icon: 6},function () {
                                  // 获得frame索引
                                  var index = parent.layer.getFrameIndex(window.name);
                                  //关闭当前frame
                                  parent.layer.close(index);
                                  window.parent.location.reload(); //刷新父页面
                              });
                          }
                      },
                      error:function(e){
                          alert("系统错误，请联系管理员！！");
                      }
                  });
                return false;
              });
            });
        </script>
    </body>

</html>